package com.logic.modular.act.task;

import com.comment.util.message.ResponseResult;
import com.logic.comment.util.JwtUtils;
import com.logic.modular.act.task.vo.TaskVo;
import com.comment.pojo.domain.logic.domain.PlayerTask;
import com.logic.modular.game.player.task.service.PlayerTaskServiceImpl;
import com.comment.pojo.domain.logic.core.CoreTaskConfig;
import com.logic.modular.gameCore.cultivate.task.service.CoreTaskConfigServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "任务行为")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/playerTaskAct")
public class PlayerTaskAction {
    private PlayerTaskServiceImpl playerTaskService;
    private CoreTaskConfigServiceImpl coreTaskConfigServiceImpl;

    @ApiOperation("基础信息列表")
    @PostMapping("/coreList")
    public ResponseResult<List<CoreTaskConfig>> getCoreTaskList() {
        return ResponseResult.success(coreTaskConfigServiceImpl.list());
    }

    @ApiOperation("获取个人任务列表")
    @PostMapping("/list")
    public ResponseResult<List<PlayerTask>> list(@RequestHeader String token) {
        Long userId = JwtUtils.getPlayerId(token);
        List<PlayerTask> list = playerTaskService.list(userId);
        return ResponseResult.success(list);
    }

    @ApiOperation("领取奖励")
    @PostMapping("/claimTaskRewards")
    public ResponseResult<PlayerTask> claimTaskRewards(
            @RequestHeader String token,
            @RequestBody TaskVo.ClaimTaskRewards claimTaskRewards
    ) {
        Long userId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(playerTaskService.claimTaskRewards(userId, claimTaskRewards.getTaskId()));
    }
}